
import java.io.IOException;
import java.util.List;
import net.siit.datatype.AnnotatedRange;
import net.siit.datatype.Range;
import net.siit.ling.TCCSeg;
import org.antlr.runtime.ANTLRFileStream;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import org.antlr.runtime.ANTLRStringStream;

/**
 *
 * @author arthit
 */
public class TCCDemo {
    
    public static void main(String args[]) {
        long startTime, stopTime;
        
        startTime = System.currentTimeMillis();

        String delim;
        String filename;
        if (args.length > 1) {
            delim = args[0];
            filename = args[1];
        } else {
            delim = ";";
            filename = args[0];
        }
        
        String test;
        test = "ตากลมตัดคำinternetเดินเกรอะไฟาสิริกิติ์ าะพระฯลฯฐๆย";
        
        ANTLRStringStream stream = new ANTLRStringStream(test);
        /*
        ANTLRFileStream stream = null;
        try {
            stream = new ANTLRFileStream(filename);
        }
        catch (IOException ex) {
            ex.printStackTrace();
        }
        */
        
        if (stream == null) {
            System.exit(1);
        }    
        stopTime = System.currentTimeMillis();
        System.out.println("init duration: " + (stopTime - startTime)/1000.0);

        startTime = System.currentTimeMillis();
        TCCSeg tccUtil = new TCCSeg();
//        List<String> clusters
//                = tccUtil.clusterizeAsString(stream);
        List<AnnotatedRange<Integer>> clusters
                = tccUtil.clusterize(stream);
        stopTime = System.currentTimeMillis();
        System.out.println("clustering duration: " + (stopTime - startTime)/1000.0);

        startTime = System.currentTimeMillis();
        System.out.print("[");
        for (AnnotatedRange<Integer> cluster : clusters) {
            System.out.print(stream.substring(cluster.getStart(), cluster.getEnd() - 1));
            System.out.print("/" + cluster.getLabel());
            System.out.print(delim);
        }
        System.out.println("]");
        stopTime = System.currentTimeMillis();
        System.out.println("print duration: " + (stopTime - startTime)/1000.0);
    }

}
